<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.2.0">


  <link rel="apple-touch-icon" sizes="180x180" href="/myblog/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/myblog/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/myblog/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/myblog/images/logo.svg" color="#222">

<link rel="stylesheet" href="/myblog/css/main.css">



<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.15.1/css/all.min.css">
  <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/animate.css@3.1.1/animate.min.css">

<script class="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"kuang-yudi.gitee.io","root":"/myblog/","images":"/myblog/images","scheme":"Gemini","version":"8.1.0","exturl":false,"sidebar":{"position":"right","display":"post","padding":18,"offset":12},"copycode":false,"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":"gitalk","storage":true,"lazyload":false,"nav":null,"activeClass":"gitalk"},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/myblog/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}};
  </script>
<meta name="description" content="深浅拷贝">
<meta property="og:type" content="article">
<meta property="og:title" content="深浅拷贝">
<meta property="og:url" content="http://kuang-yudi.gitee.io/myblog/2021/01/06/%E6%B7%B1%E6%B5%85%E6%8B%B7%E8%B4%9D/index.html">
<meta property="og:site_name" content="KY迪的个人博客">
<meta property="og:description" content="深浅拷贝">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://kuang-yudi.gitee.io/myblog/2021/01/06/%E6%B7%B1%E6%B5%85%E6%8B%B7%E8%B4%9D/%E6%95%B0%E6%8D%AE%E5%AD%98%E5%82%A8%E6%A0%88%E5%A0%86%E5%86%85%E5%AD%98.png">
<meta property="og:image" content="http://kuang-yudi.gitee.io/myblog/2021/01/06/%E6%B7%B1%E6%B5%85%E6%8B%B7%E8%B4%9D/%E5%A4%9A%E5%B1%82%E5%BC%95%E7%94%A8%E6%95%B0%E6%8D%AE.png">
<meta property="article:published_time" content="2021-01-06T08:46:47.000Z">
<meta property="article:modified_time" content="2021-02-25T04:34:08.979Z">
<meta property="article:author" content="匡宇迪">
<meta property="article:tag" content="深拷贝">
<meta property="article:tag" content="浅拷贝">
<meta property="article:tag" content="js">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://kuang-yudi.gitee.io/myblog/2021/01/06/%E6%B7%B1%E6%B5%85%E6%8B%B7%E8%B4%9D/%E6%95%B0%E6%8D%AE%E5%AD%98%E5%82%A8%E6%A0%88%E5%A0%86%E5%86%85%E5%AD%98.png">


<link rel="canonical" href="http://kuang-yudi.gitee.io/myblog/2021/01/06/%E6%B7%B1%E6%B5%85%E6%8B%B7%E8%B4%9D/">


<script class="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>
<title>深浅拷贝 | KY迪的个人博客</title>
  



  <noscript>
  <style>
  body { margin-top: 2rem; }

  .use-motion .menu-item,
  .use-motion .sidebar,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header {
    visibility: visible;
  }

  .use-motion .header,
  .use-motion .site-brand-container .toggle,
  .use-motion .footer { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle,
  .use-motion .custom-logo-image {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line {
    transform: scaleX(1);
  }

  .search-pop-overlay, .sidebar-nav { display: none; }
  .sidebar-panel { display: block; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/myblog/" class="brand" rel="start">
      <i class="logo-line"></i>
      <h1 class="site-title">KY迪的个人博客</h1>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">个人技术博客</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu">
        <li class="menu-item menu-item-home"><a href="/myblog/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a></li>
        <li class="menu-item menu-item-tags"><a href="/myblog/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a></li>
        <li class="menu-item menu-item-categories"><a href="/myblog/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a></li>
        <li class="menu-item menu-item-archives"><a href="/myblog/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</div>
        
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>

  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <section class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E5%9F%BA%E6%9C%AC%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%E5%92%8C%E5%BC%95%E7%94%A8%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%E5%8F%8A%E5%85%B6%E5%9C%A8%E5%A0%86%E6%A0%88%E4%B8%AD%E7%9A%84%E5%AD%98%E5%82%A8"><span class="nav-number">1.</span> <span class="nav-text">1. 基本数据类型和引用数据类型及其在堆栈中的存储</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E6%B7%B1%E6%B5%85%E6%8B%B7%E8%B4%9D%E7%9A%84%E5%AE%9A%E4%B9%89"><span class="nav-number">2.</span> <span class="nav-text">2. 深浅拷贝的定义</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#3-%E6%B5%85%E6%8B%B7%E8%B4%9D%EF%BC%9A%E5%AF%B9%E5%8D%95%E5%B1%82%E5%BC%95%E7%94%A8%E7%9A%84%E6%95%B0%E6%8D%AE%E6%8B%B7%E8%B4%9D"><span class="nav-number">2.1.</span> <span class="nav-text">3. 浅拷贝：对单层引用的数据拷贝</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#3-1-1-%E6%8B%B7%E8%B4%9D%E6%95%B0%E7%BB%84"><span class="nav-number">2.1.1.</span> <span class="nav-text">3.1.1 拷贝数组</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#3-1-1-%E6%8B%B7%E8%B4%9D%E5%AF%B9%E8%B1%A1"><span class="nav-number">2.1.2.</span> <span class="nav-text">3.1.1 拷贝对象</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-%E6%B7%B1%E6%8B%B7%E8%B4%9D%EF%BC%9A%E5%AF%B9%E5%A4%9A%E5%B1%82%E5%BC%95%E7%94%A8%E7%9A%84%E6%95%B0%E6%8D%AE%E6%8B%B7%E8%B4%9D"><span class="nav-number">2.2.</span> <span class="nav-text">4. 深拷贝：对多层引用的数据拷贝</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#4-1-JSON-%E6%96%B9%E6%B3%95%E5%AE%9E%E7%8E%B0%E6%B7%B1%E6%8B%B7%E8%B4%9D"><span class="nav-number">2.2.1.</span> <span class="nav-text">4.1 JSON 方法实现深拷贝</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#4-2-%E9%80%92%E5%BD%92%E5%AE%9E%E7%8E%B0%E6%B7%B1%E6%8B%B7%E8%B4%9D"><span class="nav-number">2.2.2.</span> <span class="nav-text">4.2 递归实现深拷贝</span></a></li></ol></li></ol></li></ol></div>
        </section>
        <!--/noindex-->

        <section class="site-overview-wrap sidebar-panel">
          <div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="匡宇迪"
      src="https://static.pptstore.net/picture/19/19/e1feb44f42cdf7e1202b_s.jpg">
  <p class="site-author-name" itemprop="name">匡宇迪</p>
  <div class="site-description" itemprop="description">用于记录学习web前端</div>
</div>
<div class="site-state-wrap site-overview-item animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/myblog/archives/">
        
          <span class="site-state-item-count">38</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/myblog/categories/">
          
        <span class="site-state-item-count">7</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/myblog/tags/">
          
        <span class="site-state-item-count">87</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author site-overview-item animated">
      <span class="links-of-author-item">
        <a href="https://github.com/tonykyd/tonykyd.github.io" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;tonykyd&#x2F;tonykyd.github.io" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:1303665509@qq.com" title="E-Mail → mailto:1303665509@qq.com" rel="noopener" target="_blank"><i class="fa fa-envelope fa-fw"></i>E-Mail</a>
      </span>
  </div>



        </section>
      </div>
    </div>
  </aside>
  <div class="sidebar-dimmer"></div>


    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://kuang-yudi.gitee.io/myblog/2021/01/06/%E6%B7%B1%E6%B5%85%E6%8B%B7%E8%B4%9D/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="https://static.pptstore.net/picture/19/19/e1feb44f42cdf7e1202b_s.jpg">
      <meta itemprop="name" content="匡宇迪">
      <meta itemprop="description" content="用于记录学习web前端">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="KY迪的个人博客">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          深浅拷贝
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2021-01-06 16:46:47" itemprop="dateCreated datePublished" datetime="2021-01-06T16:46:47+08:00">2021-01-06</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2021-02-25 12:34:08" itemprop="dateModified" datetime="2021-02-25T12:34:08+08:00">2021-02-25</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/myblog/categories/javascript/" itemprop="url" rel="index"><span itemprop="name">javascript</span></a>
        </span>
    </span>

  
    <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="far fa-eye"></i>
      </span>
      <span class="post-meta-item-text">阅读次数：</span>
      <span id="busuanzi_value_page_pv"></span>
    </span>
</div>

            <div class="post-description">深浅拷贝</div>
        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
        <h2 id="1-基本数据类型和引用数据类型及其在堆栈中的存储"><a href="#1-基本数据类型和引用数据类型及其在堆栈中的存储" class="headerlink" title="1. 基本数据类型和引用数据类型及其在堆栈中的存储"></a>1. 基本数据类型和引用数据类型及其在堆栈中的存储</h2><p>基本数据类型：String、Number、boolean、null、undefined。<br>引用类型：Object(包含 Array)</p>
<p>1.1 基本数据类型的值直接保存在栈内存中<br>1.2 引用数据类型声明的变量保存在栈内存中，变量的值为对象、数组保存在堆内存中的地址<br>如图：<br><img src="%E6%95%B0%E6%8D%AE%E5%AD%98%E5%82%A8%E6%A0%88%E5%A0%86%E5%86%85%E5%AD%98.png" alt="不同数据的栈、堆内存"></p>
<h2 id="2-深浅拷贝的定义"><a href="#2-深浅拷贝的定义" class="headerlink" title="2. 深浅拷贝的定义"></a>2. 深浅拷贝的定义</h2><p>2.1 浅拷贝： 将原对象或原数组的引用直接赋给新对象，新数组，新对象／数组只是原对象的一个引用</p>
<p>理解：拷贝的是地址，指向堆内存中同样的内容(拷贝后更改属性会改变原数据)</p>
<p>2.2 深拷贝： 创建一个新的对象和数组，将原对象的各项属性的“值”（数组的所有元素）拷贝过来，是“值”而不是“引用”</p>
<p>理解：在堆内存中拷贝(创建新的内存地址，拷贝后更改属性不会改变原数据)</p>
<p><font color="blue">总结：对于所有的拷贝的方法，就看有没有把所有引用数据都拷贝(创建新的堆内存)，所以一般用递归。</font></p>
<h3 id="3-浅拷贝：对单层引用的数据拷贝"><a href="#3-浅拷贝：对单层引用的数据拷贝" class="headerlink" title="3. 浅拷贝：对单层引用的数据拷贝"></a>3. 浅拷贝：对单层引用的数据拷贝</h3><h4 id="3-1-1-拷贝数组"><a href="#3-1-1-拷贝数组" class="headerlink" title="3.1.1 拷贝数组"></a>3.1.1 拷贝数组</h4><p><strong>1. 遍历添加到新数组中</strong><br><strong>2. slice()截取一部分元素片段组成新数组</strong><br><strong>3. concat()与空数组合并返回新数组</strong><br>注：只要是创建了新数组就是创建了新的堆内存</p>
<h4 id="3-1-1-拷贝对象"><a href="#3-1-1-拷贝对象" class="headerlink" title="3.1.1 拷贝对象"></a>3.1.1 拷贝对象</h4><p><strong>1. 遍历添加到新对象中</strong><br><strong>2. ES6 的 Object.assign 对象的合并，将源对象（source）的所有可枚举属性，复制到目标对象（target），并返回合并后的 target</strong><br><strong>3. ES6 扩展运算符{…obj}</strong><br>注：同样，只要是创建了新对象就是创建了新的堆内存</p>
<h3 id="4-深拷贝：对多层引用的数据拷贝"><a href="#4-深拷贝：对多层引用的数据拷贝" class="headerlink" title="4. 深拷贝：对多层引用的数据拷贝"></a>4. 深拷贝：对多层引用的数据拷贝</h3><p><img src="%E5%A4%9A%E5%B1%82%E5%BC%95%E7%94%A8%E6%95%B0%E6%8D%AE.png" alt="多层引用的数据"><br>3.1 中的方法都只能对一层进行拷贝，对多层引用数据内都是拷贝的地址</p>
<h4 id="4-1-JSON-方法实现深拷贝"><a href="#4-1-JSON-方法实现深拷贝" class="headerlink" title="4.1 JSON 方法实现深拷贝"></a>4.1 JSON 方法实现深拷贝</h4><p>推荐只有可以转成 JSON 格式的对象才可以这样用</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">JSON.parse(JSON.stringify(XXXX))</span><br></pre></td></tr></table></figure>

<p>JSON.parse() 方法用于将一个 JSON 字符串转换为对象–（反序列化）</p>
<p>JSON.stringify() 方法是将一个 JavaScript 值(对象或者数组)转换为一个 JSON 字符串–(序列化）</p>
<p>序列化的缺点：<br>① 不支持基本数据类型的 undefined，序列化后将其省略<br>② 不支持函数<br>③ NaN,Infinity 序列化的结果是 null<br>④ 无法拷贝对象原型链上的属性和方法</p>
<h4 id="4-2-递归实现深拷贝"><a href="#4-2-递归实现深拷贝" class="headerlink" title="4.2 递归实现深拷贝"></a>4.2 递归实现深拷贝</h4><p>原理：递归的条件就是看拿到的值是否为引用类型，如果是则继续遍历，这样每层都创建了新的引用类型数据(创建了新的堆内存)，直到拿到简单数据类型，此时才进行赋值</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line">let obj &#x3D; [&#123; name: &#39;zs&#39; &#125;, &#123; age: 28 &#125;]</span><br><span class="line"></span><br><span class="line">    function copy(obj) &#123;</span><br><span class="line">      &#x2F;&#x2F;首先判断需要拷贝的“东西”是什么类型</span><br><span class="line">      if (typeof obj !&#x3D;&#x3D; &#39;object&#39; || obj &#x3D;&#x3D; null) &#123;</span><br><span class="line">        &#x2F;&#x2F; 如果不是对象或者为null则返回</span><br><span class="line">        return;</span><br><span class="line">      &#125;</span><br><span class="line">      &#x2F;&#x2F;判断是数组&#x2F;对象，并开启对应堆内存</span><br><span class="line">      let newobj &#x3D; Array.isArray(obj) ? [] : &#123;&#125;;</span><br><span class="line">      &#x2F;&#x2F;obj是数组类型，下面的i就是index；obj是对象，i就是key</span><br><span class="line">      for (let i in obj) &#123;</span><br><span class="line">        &#x2F;* hasOwnProperty(name)指示一个对象自身（不包括原型链）</span><br><span class="line">        是否具有指定名称的属性。如果有返回true，如果没有返回false。 *&#x2F;</span><br><span class="line">        if (obj.hasOwnProperty(i)) &#123;</span><br><span class="line">          &#x2F;&#x2F;拿到属性值判断是否为引用数据类型，是则递归</span><br><span class="line">          newobj[i] &#x3D; typeof obj[i] &#x3D;&#x3D;&#x3D; &#39;object&#39; ? copy(obj[i]) : obj[i];</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line">      return newobj</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    console.log(copy(obj));</span><br><span class="line"></span><br><span class="line">    &#x2F;* for…in循环可应用于对象的复制，</span><br><span class="line">    不过其有一个缺点，就是会从原型属性里继承prototype()属性。 *&#x2F;</span><br><span class="line">    let array &#x3D; [1, 2, 3, 4, 5]</span><br><span class="line">    Array.prototype.age &#x3D; 13</span><br><span class="line">    console.log(array);</span><br><span class="line">    var result &#x3D; []</span><br><span class="line">    for (let i in array) &#123;</span><br><span class="line">      result.push(array[i]);</span><br><span class="line">      &#x2F;&#x2F; console.log(array[i]);</span><br><span class="line">      console.log(i);</span><br><span class="line">    &#125;</span><br><span class="line">    console.log(result.join(&#39;,&#39;));</span><br><span class="line"></span><br></pre></td></tr></table></figure>

    </div>

    
    
    

    <footer class="post-footer">
          <div class="followme">
  <span>欢迎关注我的其它发布渠道</span>

  <div class="social-list">

      <div class="social-item">
        <a target="_blank" class="social-link" href="/myblog/images/wechat_channel.jpg">
          <span class="icon">
            <i class="fab fa-weixin"></i>
          </span>

          <span class="label">WeChat</span>
        </a>
      </div>
  </div>
</div>

          <div class="post-tags">
              <a href="/myblog/tags/%E6%B7%B1%E6%8B%B7%E8%B4%9D/" rel="tag"># 深拷贝</a>
              <a href="/myblog/tags/%E6%B5%85%E6%8B%B7%E8%B4%9D/" rel="tag"># 浅拷贝</a>
              <a href="/myblog/tags/js/" rel="tag"># js</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/myblog/2021/01/06/CSS%E5%B1%85%E4%B8%AD%E6%96%B9%E5%BC%8F/" rel="prev" title="CSS居中方式">
                  <i class="fa fa-chevron-left"></i> CSS居中方式
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/myblog/2021/01/06/CSS%E6%96%B0%E5%B8%83%E5%B1%80display-grid/" rel="next" title="CSS新布局display:grid">
                  CSS新布局display:grid <i class="fa fa-chevron-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






    <div class="comments" id="gitalk-container"></div>

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      const activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      const commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>
</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">


<div class="copyright">
  &copy; 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">匡宇迪</span>
</div>
<div class="busuanzi-count">
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>

    </div>
  </footer>

  
  <script src="//cdn.jsdelivr.net/npm/animejs@3.2.1/lib/anime.min.js"></script>
<script src="/myblog/js/utils.js"></script><script src="/myblog/js/motion.js"></script><script src="/myblog/js/next-boot.js"></script>

  
<script src="/myblog/js/local-search.js"></script>






  
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>






<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/gitalk@1.7.0/dist/gitalk.css">

<script>
NexT.utils.loadComments('#gitalk-container', () => {
  NexT.utils.getScript('//cdn.jsdelivr.net/npm/gitalk@1.7.0/dist/gitalk.min.js', () => {
    var gitalk = new Gitalk({
      clientID    : '1926f8a1c453a1121d8d',
      clientSecret: '426722f9eef7599f8ebb3220379e704ea007a5f2',
      repo        : '',
      owner       : '',
      admin       : [''],
      id          : '7a5cb0b49fef9d50e6ce85518972571d',
        language: '',
      distractionFreeMode: true
    });
    gitalk.render('gitalk-container');
  }, window.Gitalk);
});
</script>

</body>
</html>
